package com.unitd.base.module.consumer.comm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 集成swaggerm,实现自动化配置获取api接口文档信息
 * 这是Swagger2的配置文件，必须需要此文件
 * Swagger与工程结合需要引入依赖，已在pom.xml中表明，一共2个依赖
 * swagger2文档的默认地址是 .../swagger-ui.html
 * https://swagger.io/
 *
 * @author Hudan
 * @version 1.0
 * @filename WechatData.java
 * @copyright www.unitd.com
 * @date 2020-07-09
 */
@Configuration
@EnableSwagger2
@ComponentScan(basePackages = "com.unitd.base")
public class SwaggerConfig {

    /**
     * 定义swagger的api扫描的路径
     *
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.unitd.base"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * swagger首页需要展示的信息
     *
     * @return 首页展示信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 文档标题
                .title("UNITD-SHOP 接口信息定义")
                // 文档描述
                .description("更多Spring Boot相关代码请关注：https://gitee.com/hudan729046/")
                .contact(new Contact("Hudan", "https://gitee.com/hudan729046/", "hudan729046@hotmail.com"))
                .version("1.0")
                .build();
    }
}
